--- %%NOBANNER%% -->
![]() | ![]() |
/*------------------<-- Start of Description -->--------------------\ | Sample size for one mean; | |--------------------<-- End of Description -->---------------------| |--------------------------------------------------------------------| |--------------<-- Start of Files or Arguments Needed -->-----------| | Arguments: | | - Required: | | std = standard deviation | | y1 = true mean under null hypothesis | | min_y2 = smallest possible alternative hypothesis mean | | - Optional: | | max_y2 = largest possible alternative hypothesis mean | | inc_y2 = increment value for range of y2 | | alpha = type 1 error, e.g. .01 or .05, default=.o5 | | sides = 1 or 2 for 1 or 2 sided test, default=2 | | power = desired power, e.g. .80, .90, default=.80 | | plot = 'P' for line printer plot of sample size vs y2 | | 'G' for SAS/GRAPH plot of sample size vs y2 | | unit = units for mean, e.g. mg, lbs., cm, etc. | | Output: Sample size for null hypothesis mean of y1 vs alternative | | hypothesis means ranging from min_y2 to max_y2 | |---------------<-- End of Files or Arguments Needed -->------------| |--------------------------------------------------------------------| |----------------<-- Start of Example and Usage -->-----------------| | Example: %mn1_ss(alpha=.05,sides=2,power=.8,std=1, y1=0, | | min_y2=.3, max_y2=3,inc_y2=.1,plot=p,unit=kg); | | Usage: %mn1_ss(ALPHA=.05,SIDES=2,POWER=.80,Y1=.,MIN_Y2=., | | MAX_Y2=.,INC_Y2=.,STD=.,PLOT= , UNIT=); | | Reference: Bergstralh, EJ. SAS macros for sample size and power | | calculations. Proceedings of the 9th annual SAS Users | | Group International Conference. | | Equation #2. | \-------------------<-- End of Example and Usage -->---------------*/ %MACRO mn1_ss(ALPHA=.05,SIDES=2,POWER=.80,Y1=.,MIN_Y2=., MAX_Y2=.,INC_Y2=.,STD=.,PLOT= , UNIT=); /*--------------------------------------------\ | Author: Michael Riggs and Eric Bergstralh;| | Created: November 16, 1992; | | Modified: January 9, 1998; | | Purpose: Sample Size for One means; | \--------------------------------------------*/ OPTIONS MISSING=' ' NOCENTER; %LET PLOT=%UPCASE(&PLOT); DATA T1; ALPHA=&ALPHA; SIDES=&SIDES; Y1=&Y1; MIN_Y2=&MIN_Y2; MAX_Y2=&MAX_Y2; INC_Y2=&INC_Y2; POWER=&POWER; STD=&STD; ZALPHA=(PROBIT(1-ALPHA))*(SIDES=1) + (PROBIT(1-ALPHA/2))*(SIDES=2); ZBETA=PROBIT(POWER); IF MAX_Y2=. THEN DO; MAX_Y2=MIN_Y2+1; INC_Y2=MIN_Y2+2; *NEED 1 EXEC OF DO; END; TY1=Y1; TSTD=STD; DO Y2=MIN_Y2 TO MAX_Y2 BY INC_Y2; N=(TSTD*(ZALPHA+ZBETA)/(Y2-TY1))**2; DF=ceil(N)-1; N1=CEIL( N*(df+3)/(df+1) ); *increase n for t-test, 1/9/98; OUTPUT; END; LABEL Y1="Null hyp.*Mean* (&UNIT)" Y2="Alt. hyp.*Mean* (&UNIT)"; FOOTNOTE1 ' '; RUN; PROC PRINT SPLIT='*'; id y1; var y2 n1; TITLE2 H=2 ' '; TITLE3 'SAMPLE SIZE REQUIREMENTS FOR ONE MEAN VS A CONSTANT'; TITLE4 "Alpha=&alpha, Sides=&sides, STD=&std, Power=&power, Null hypothesis: mean=&y1"; %IF "&MAX_Y2" NE "" %THEN %DO; %IF &PLOT= P %THEN %DO; PROC PLOT NOLEGEND; PLOT N1*Y2/ HAXIS=&MIN_Y2 TO &MAX_Y2 BY &INC_Y2; LABEL N1="Sample size" y2="Alt. hyp. mean(&unit)"; %END; %ELSE %IF &PLOT= G %THEN %DO; PROC GPLOT ; PLOT N1*Y2; SYMBOL1 font= v=none i=join l=1; LABEL N1="Sample size" y2="Alt. hyp. mean(&unit)"; run; %END; RUN; %END; %MEND mn1_ss;